package com.qiaofang.repository;

import com.qiaofang.entity.CompanyRelation;
import com.qiaofang.entity.Department;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CompanyRelationRepository extends JpaRepository<CompanyRelation, Long>, JpaSpecificationExecutor {

    @Query(value = "from CompanyRelation p where p.devCompany = :companyId and p.delFlag = 0 ")
    List<CompanyRelation> listCompanyId(@Param(value = "companyId") Long companyId);

    @Query(value = "from CompanyRelation d where d.agentCompany in (:companyIds) and d.delFlag = 0")
    List<CompanyRelation> getCompanyRelationList(@Param(value = "companyIds") List<Long> companyIds);

    /**
     * 同过分销公司id查询一个公司外部关系
     *
     * @param agentId
     * @return CompanyRelation
     */
    @Query(value = "from CompanyRelation a where a.agentCompany = :agentId and a.delFlag = 0")
    CompanyRelation findByAgentId(@Param(value = "agentId") Long agentId);

}
